package com.example.demo.web;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.jfinal.kit.HttpKit;

@RestController
@RequestMapping("/api")
public class ApiController {
	
	@Autowired
	ObjectMapper mapper;
	
	@Autowired
	HttpServletRequest request;

	@RequestMapping("user")
	public String user() throws JsonProcessingException {
		
		//读取post 的json参数
		String readData = HttpKit.readData(request);
		System.out.println("----------------post 请求参数--------------------");
		System.out.println(readData);
		System.out.println("----------------post 请求参数 end--------------------");
		
		Map<String, Object> user = new HashMap<String, Object>();
		user.put("name", "gwx");
		user.put("sex", "男");
		return mapper.writeValueAsString(user);
	}
	
	
	
}	
